<?php
if ( !class_exists( "Amounts_3d" ) )
{
    include_once( "class_3d/Amounts_3d.php" );
}
class Amounts_5h extends Amounts_3d
{

    public function getAmountsDataById( $bettype, $user_id, $subid = 0, $xyid = -1 )
    {
        $reVal = false;
        $sql = "SELECT * FROM ".$this->table_name;
        $sql .= " WHERE";
        $sql .= " bettype = ".$bettype;
        $sql .= " AND subid = ".$subid;
        $sql .= " AND user_id = ".$user_id;
        $sql .= " AND xyid = ".$xyid;
        $sql .= " LIMIT 1";
        $result = $this->db->query( $sql );
        if ( $result )
        {
            $row = mysql_fetch_array( $result );
            $reVal = $row;
        }
        else
        {
            $reVal = false;
        }
        return $reVal;
    }

    public function check_Amount_255( $lotto_id, $bettype, $numbers, $val, $subid = 0 )
    {
        $tblName = "autorate_".$this->tbl;
        $cfgName = "autorate_config_".$this->tbl;
        $reVal = array();
        $sql = "";
        if ( is_array( $numbers ) )
        {
            $NumsArray = implode( ",", $numbers );
            $sql = "!!SELECT amount_255,"." (Select max(total) from {$tblName} where lotto_id={$lotto_id} AND numbers in ({$NumsArray}) AND bettype = A.bettype_id AND subid = 0) as total"." FROM {$cfgName} A WHERE bettype_id = ".$bettype." AND A.subid = {$subid}";
        }
        else
        {
            $sql = "!!SELECT amount_255,"." (Select max(total) from {$tblName} where lotto_id={$lotto_id} AND numbers = '{$numbers}' AND bettype = A.bettype_id AND subid = 0) as total"." FROM {$cfgName} A WHERE bettype_id = ".$bettype." AND A.subid = {$subid}";
        }
        $result = $this->db->query( $sql );
        $amount_255 = 0;
        $total = 0;
        if ( $result )
        {
            $row = mysql_fetch_array( $result );
            $amount_255 = intval( $row[0] );
            $total = intval( $row[1] ) + 0;
            if ( $total < 0 )
            {
                $total = 0;
            }
        }
        if ( 0 < $amount_255 && $amount_255 < $total + $val )
        {
            if ( is_array( $numbers ) )
            {
                $nval = $amount_255 - $val;
                $sql = "Select numbers from {$tblName} where lotto_id={$lotto_id} AND numbers in ({$NumsArray}) AND bettype = {$bettype} AND subid = 0 and total>{$nval}";
                $result = $this->db->query( $sql );
                while ( $row = mysql_fetch_array( $result ) )
                {
                    array_push( $reVal, $row[0] );
                }
            }
            array_push( $reVal, $numbers );
        }
        return $reVal;
    }

}

?>